#pragma once

#include "stdafx.h"

namespace natrium {
	namespace input {
		class Joystick
		{
		public:
			Joystick(unsigned int deviceID);
			virtual ~Joystick();

			void update();

			//---- [Query current state] ----
			unsigned int getJoystickID() const;

			unsigned int getNumAxes() const;
			unsigned int getNumButtons() const;

			 //bit awkward, but this is the format that GLFW passes...
			float getAxis(unsigned int index) const;
			float* getPosition() const;
			unsigned char getButton(unsigned int buttonIndex) const;
			bool isPressed(unsigned int buttonIndex) const;

			//---- [Events] ----
			struct Moved {
				std::vector<float> mCurrentPosition;
				std::vector<float> mOldPosition;
				std::vector<float> mDelta;
				unsigned int mJoystickID;

				Moved(unsigned int joystickID, std::vector<float>&& oldPosition, float* newPosition);
			};

			struct ButtonPressed {
				unsigned int mButtonID;
				unsigned int mJoystickID;

				ButtonPressed(unsigned int joystickID, unsigned int buttonID);
			};

			struct ButtonReleased {
				unsigned int mButtonID;
				unsigned int mJoystickID;

				ButtonReleased(unsigned int joystickID, unsigned int buttonID);
			};

		private:
			unsigned int mJoystickID;

			unsigned int mNumAxes;
			unsigned int mNumButtons;

			//these types are chosen because of the GLFW implementation :(
			float* mPosition;
			unsigned char* mButtonState;
		};
	}
}